#!/bin/sh


export PATH=/usr/local/bin:$PATH

workdir=$(cd $(dirname $0); pwd)

chkFun(){
fi [ -x $1 ];then
echo 0
else
echo 1
fi
}

pngFile=$workdir"/pngquant"
jpegFile=$workdir"/jpegoptim"
test=$workdir"testBash"

p=`chkFun $pngFile`
p=`chkFun $jpegFile`

if [[ $p != 0 ]] || [[ $g != 0 ]]; then
echo "确定脚本存在或者有执行权限"
echo $pngFile
echo $jpegFile
exit 1
fi

PNG_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.png')

echo "资源正在压缩中...."

for file in $PNG_FILES
do
` $workdir/pngquant -f -o $file --skip-if-larger --quality 65-80 $file `
result=$?;
if [ $result == 98 ];then
echo "$file result:压缩完成..."
else
echo  "$file result:压缩失败:$result..."
fi

done

if [ "$PNG_FILES" != "" ];then
git add $PNG_FILES
fi




